package mx.vlabs.wssb.ejb.bean;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.ejb.Stateless;
import javax.jws.WebService;

import org.apache.log4j.Logger;

import mx.vlabs.wssb.ejb.local.SandBoxEjbLocal;
import mx.vlabs.wssb.model.dto.ChildDTO;
import mx.vlabs.wssb.model.dto.DummyDTO;

@Stateless
@WebService(serviceName="sandBoxService")
public class SandBoxEjbBean implements SandBoxEjbLocal {
	
	private Logger log = Logger.getLogger(SandBoxEjbBean.class);
	
	@Override
	public void emptyMethod() {
		// TODO Auto-generated method stub
		log.info("empty method executed");

	}

	@Override
	public String sayHello(String name) {
		// TODO Auto-generated method stub
		log.info("saying hello");
		
		return "Hi "+name;
	}

	@Override
	public DummyDTO readDTO() {
		// TODO Auto-generated method stub
		log.info("reading dto");
		
		DummyDTO dto = new DummyDTO();
	
		dto.setId(4L);
		dto.setStringVal("STRING VALUE");
		dto.setDateVal(new Date());
		dto.setChildDTO(new ChildDTO("child value"));
		dto.setStringList(new ArrayList<String>(){{
			add("item1");
			add("item2");
			add("item3");
		}});
		
		dto.setBoolVal(true);
		
		List<ChildDTO> childList = new ArrayList<ChildDTO>();
		
		childList.add(new ChildDTO("childItem1"));
		childList.add(new ChildDTO("childItem2"));
		childList.add(new ChildDTO("childItem3"));
		childList.add(new ChildDTO("childItem4"));
		
		log.info(childList);
		
		dto.setChildDTOList(childList);
		
		return dto;
	}

	@Override
	public void printDTO(DummyDTO dto) {
		// TODO Auto-generated method stub
		log.info("printingDTO hello");
		
		log.info("id "+dto.getId());
		log.info("stringVal "+dto.getStringVal());
		log.info("dateVal "+dto.getDateVal());
		
		log.info("childDTO val "+dto.getChildDTO().getStringVal());
		
		if(dto.getStringList()!=null)
		for(String str : dto.getStringList()){
			log.info("printing stringlist "+str);
		}
		
		if(dto.getChildDTOList()!=null)
		for(ChildDTO child : dto.getChildDTOList()){
			log.info("printing childDTO "+child.getStringVal());
		}
		
	}

	@Override
	public DummyDTO updateDTO(DummyDTO dto) {
		// TODO Auto-generated method stub
		
		dto.setId(999L);
		
		return dto;
	}

}
